(function () {
    var defaultTime=moment(new Date).format('YYYY-MM-DD');
    jQuery('#paidDate').val(defaultTime);
    jQuery('#paymentDate').val(defaultTime);
    var contractId=jQuery('#contractId').val();
    var contractType=jQuery('#contractType').val();
    var contractSum=jQuery('#paySum1').val();//合同总额
    var paySum;//剩余回款总额
    var remain;//剩余开票金额
    var oldpay;
    var oldpayment;
    var sumScheduleSum=jQuery('#sumScheduleSum').val();
    if(jQuery('#divideScales').val()=="0"){
    	jQuery('#tab1').css("display","none");
    }
//获取回款计划tabs页面数据 服务器分页
    var serverData = {};
    var	serverTable;
    jQuery(document).ready(function () {
        serverTable = jQuery('#scheduleTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/paySchedule/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'fund'
                },
                {
                    data: 'amount'
                },
                {
                    data:'payDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data:'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
        
        var serverData5 = {};
        var	serverTable5;
        serverTable5 = jQuery('#resultScaleTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/contract/getDivideScale',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'functionary'
                },
                {
                	data: 'belongArea'
                },
                {
                    data: 'scaleDivide'
                },
                {
                    data: 'percent'
                },
                {
                    data: 'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
//获取回款历史tabs页面数据 服务器分页
    var serverData1 = {};
    var	serverTable1;
    jQuery(document).ready(function () {
        serverTable1 = jQuery('#payTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/payment/payHistory/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData1);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'paidSum'
                },
                {
                    data: 'paidWay'
                },
                {
                    data:'paidDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY-MM-DD');
                        else
                            return '';
                    }
                },
                {
                    data:'payMan'
                },
                {
                    data:'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
        
    });
//获取开票历史tabs页面数据 服务器分页
    var serverData2 = {};
    var	serverTable2;
    jQuery(document).ready(function () {
        serverTable2 = jQuery('#paymentTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/payment/paymentHistory/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData2);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'paymentSum'
                },
                {
                    data:'paymentDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY-MM-DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'paymentMan'
                },
                {
                    data:'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
//获取回款-计划tabs页面数据 服务器分页
    var serverData3 = {};
    var	serverTable3;
    jQuery(document).ready(function () {
        serverTable3 = jQuery('#paidScheduleTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/payment/payPlan/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData3);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'fund'
                },
                {
                    data: 'scheduleSum'
                },
                {
                    data:'paidStage'
                },
                {
                    data:'schedulePayDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data:'deviationDate'
                },
                {
                    data:'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
//获取开票-计划tabs页面数据 服务器分页
    var serverData4 = {};
    var	serverTable4;
    jQuery(document).ready(function () {
        serverTable4 = jQuery('#paymentScheduleTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/payment/paymentPlan/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData4);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'fund'
                },
                {
                    data:'paymentStage'
                },
                {
                    data:'schedulePayDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data:'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
})();